/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.util;

import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author riccardo
 */
@ManagedBean
@Named(value = "context")

@RequestScoped
public class Context {

    /**
     * Creates a new instance of Context
     */
    private String ID;
    private String URL;

    public String getURL() throws IOException {
        
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String url = request.getRequestURL().toString();
        String uri = request.getRequestURI();
        System.out.println("url = " + url);
        System.out.println("uri = " + uri);
        FacesContext.getCurrentInstance().getExternalContext().redirect(url);
        return url;
    }    

    public void setURL(String URL) {
        this.URL = URL;
    }

    public Context() {
    }

    public String getID() {
        String ret;
        try {
            ret = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
        } catch (Exception e) {
            ret = "not logged";
        }
        return ret;
    }

}
